<template>
    <addEditMeetingView ref="addEditMeetingView" />
    <div class="app-table">
        <div class="app-body">
            <div class="app-search">
                <el-form :inline="true" class="demo-form-inline" v-model="form">
                    <el-form-item label="选择日期" style="width:200px">
                        <el-config-provider :locale="locale">
                            <el-date-picker v-model="form.startTime" type="date" value-format="YYYY-MM-DD"
                                placeholder="选择日期" :size="size" />
                        </el-config-provider>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">搜索</el-button>
                        <el-button type="success" @click="add">添加</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-table size="small" :data="list" border :row-class-name="tableRowClassName">
                <el-table-column prop="id" label="序号" width="60" />
                <el-table-column prop="meetId" label="会议Id" width="70" />
                <el-table-column prop="startTime" label="开会日期" width="100" />
                <el-table-column prop="participantsName" label="开会人员" />
                <el-table-column prop="meetName" label="会议名称" width="160" />
                <el-table-column prop="submitter" label="操作者" width="70" />
                <el-table-column prop="submitTime" label="提交时间" width="160" />
                <el-table-column label="操作" width="200">
                    <template style="display: block" #default="scope">
                        <el-button size="small" type="success" @click="editMeeting(scope.row.meetId)">编辑
                        </el-button>
                        <el-button size="small" type="danger" @click="deleteMeeting(scope.row.meetId)">删除
                        </el-button>
                        <el-button size="small" type="warning" @click="exportExcel(scope.row)">下载
                        </el-button>
                    </template>
                </el-table-column>
                <template v-slot:empty>
                    <el-empty description="暂无数据"></el-empty>
                </template>
            </el-table>
            <div style="margin-top: 10px">
                <el-config-provider :locale="locale">
                    <el-pagination :total="total" :page-size="limit" :current-page="page"
                        :page-sizes="[5, 10, 20, 30, 40, 50, 100]" layout="total, sizes, prev, pager, next, jumper"
                        @size-change="changePageSize" @current-change="changeCurrentPage">
                    </el-pagination>
                </el-config-provider>
            </div>
        </div>
        <bottomView></bottomView>
    </div>
</template>
<script>
import { ElConfigProvider, ElMessageBox, ElMessage } from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { httpService } from "@/utils/httpService";
import bottomView from "@/components/bottom.vue";
import addEditMeetingView from "../../components/attendance/addEditMeeting";

export default {
    name: "teacherListView",
    data() {
        return {
            type: 0,
            title: "",
            page: 1,
            pageSize: 10,
            total: 0,
            limit: 10,
            list: [],
            holiday: "",
            meetId: "",
            user: {},
            form: {
                startTime: ""
            }
        };
    },
    components: {
        addEditMeetingView,
        ElMessageBox,
        bottomView,
        ElMessage
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    mounted() {
        this.getMeetingList();
        this.user = JSON.parse(sessionStorage.getItem("user"))
    },
    methods: {
        add() {
            this.$refs.addEditMeetingView.title = '添加会议';
            this.$refs.addEditMeetingView.dialogFormVisible = true
        },
        editMeeting(meetId) {
            this.$refs.addEditMeetingView.title = '修改会议';
            this.$refs.addEditMeetingView.dialogFormVisible = true;
            this.$refs.addEditMeetingView.getMeetingById(meetId);
        },
        deleteMeeting(meetId) {
            ElMessageBox.confirm("确定要删除本条记录吗？", "提醒", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    httpService("/pythonApi/attendanceApi/deleteMeeting", "meetId=" + meetId, "post").then(
                        (data) => {
                            if (data.code == 200) {
                                ElMessage.success("删除成功");
                                this.getMeetingList();
                            } else {
                                ElMessage.error("删除失败，请重试！");
                            }
                        }
                    );
                })
                .catch(() => {
                });
        },
        reloadData() {
            this.page = 1;
            this.getMeetingList()
        },
        onSubmit() {
            if (this.holiday == null) {
                this.holiday = ""
            }
            this.page = 1;
            this.getMeetingList();
        },
        // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
        changePageSize(size) {
            this.pageSize = size;
            this.limit = size;
            this.getMeetingList();
        },

        // 改变页码，page：回调参数，表示当前选中的“页码”
        changeCurrentPage(page) {
            this.page = page;
            this.getMeetingList();
        },
        getMeetingList() {
            httpService(
                "/pythonApi/attendanceApi/getMeetingList",
                {
                    page: this.page,
                    limit: this.limit,
                    startTime: this.form.startTime,
                    // submitter: this.user.teacherNumber
                },
                "get"
            ).then((data) => {
                this.list = data.data;
                this.total = data.total;
                this.pageCount = data.pages;
            });
        },
        exportExcel(row) {
            let config = { "responseType": "blob" };
            httpService("/pythonApi/attendanceApi/getMeetingAttendanceData",
                {
                    meetId: row.meetId
                }, 'get', config).then(
                    (data) => {
                        let link = document.createElement('a'), fileUrl = window.URL.createObjectURL(new Blob([data]));
                        link.style.display = 'none';
                        link.href = fileUrl;
                        link.setAttribute('download', row.startTime.toString() + '会议考勤表.xlsx');
                        document.body.appendChild(link);
                        link.click();
                        document.body.removeChild(link);
                        window.URL.revokeObjectURL(fileUrl)
                    }
                )
        }
    },
};
</script>
<style scoped>
.app-table {
    background: #eff3f5;
    padding: 10px;
    width: calc(100vw - 192px);
}

.app-search {}


.app-body {
    background: white;
    padding: 20px 20px 10px 20px;
    margin-bottom: 10px;
    min-height: calc(100vh - 242px);
}
</style>
